package com.song.pj.arithmetic.controller;

import com.song.pj.arithmetic.service.ArithemticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ArithmeticController {
    //Controller类内部的异常处理方法（谁来调用它？）\
    //@ExceptionHandler注解描述的方法为异常处理方法
    //@ExceptionHandler注解内部定义的异常类型为他描述的方法可以处理的异常类型
//    @ExceptionHandler(ArithmeticException.class)
//    @ResponseBody
//    public String doHandleArithmeticException(ArithmeticException e){
//        return "the excepiton msg is"+e.getMessage();
//    }

    @ResponseBody
    @RequestMapping("/doCompute/{n1}/{n2}")
    public String doComputer(@PathVariable Integer n1,
                             @PathVariable Integer n2){
//        try{
            Integer reult=n1/n2;//异常没有处理，异常抛给dispacherServlet
            return "The Result is"+reult;
//        }catch (ArithmeticException e){
//            e.printStackTrace();
//            return "计算过程中出现了异常，具体信息为:"+ e.getMessage();
//        }

    }
    @Autowired
    private ArithemticService arithemticService;
    @ResponseBody
    @RequestMapping("/doSum/{nums}")
    public String doSum(@PathVariable Integer ...nums){
        return "求和结果为"+arithemticService.sum(nums);
    }

}
